package com.dongdongshop.servcice.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbItemCatMapper;
import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.pojo.TbItemCatExample;
import com.dongdongshop.pojo.TbItemExample;
import com.dongdongshop.service.ItemCatService;
import com.dongdongshop.util.PageBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class ItemCatServiceImpl implements ItemCatService {
    @Resource
    private TbItemCatMapper itemCatMapper;
    @Resource
    private TbItemMapper itemMapper;

    @Override
    public List<TbItemCat> getItemCatInfo(Integer parentId) {
        Long parentIdl = Long.valueOf(parentId);
        List<TbItemCat> list = itemCatMapper.getItemCatInfo(parentIdl);
        return list;
    }

    @Override
    public TbItemCat updateInfo(Integer id) {
        TbItemCat itemCat = itemCatMapper.selectByPrimaryKey(Long.valueOf(id));
        return itemCat;
    }

    @Override
    public void update(TbItemCat itemCat) {
        itemCatMapper.updateByPrimaryKeySelective(itemCat);
    }

    @Override
    public void insertItemCat(TbItemCat itemCat) {
        itemCatMapper.insertSelective(itemCat);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        itemCatMapper.deleteBatch(ids);
    }

    @Override
    public TbItemCat getItemCatInfoById(Long category1Id) {
        return itemCatMapper.selectByPrimaryKey(category1Id);
    }

    @Override
    public List<TbItem> getItemInfoById(Long id) {
        TbItemExample example = new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(id);//根据goodsid查询
        criteria.andStatusEqualTo("1");//查询正常状态的商品
        example.setOrderByClause("is_default desc");//按照是否默认排序，保证默认的数据在第一个

        return itemMapper.selectByExample(example);
    }
}
